//moved to jquery.magicmap2.js
String.prototype.format = function () {
    var args = arguments;
    return this.replace(/\{(\d+)\}/g, function (m, n) { return args[n]; });
};
String.prototype.escape = function () {
    var args = arguments;
    return this.replace(/</g, '').replace(/>/g, '');
};
formatfilesize = function(bytes){
    var bytes = bytes.toFixed(2);
    if(bytes<1024){
        return "{0} bytes".format(bytes);
    } else if(bytes<1024*1024){
        return "{0} KB".format((bytes/(1024)).toFixed(1));
    }else if(bytes<1024 * 1024 * 1024){
        return "{0} MB".format((bytes/(1024 * 1024)).toFixed(1));
    }
    return "{0} GB".format((bytes/(1024 * 1024 * 1024)).toFixed(2));
};
formatutc = function(date, format){
    /*
     * eg:format="yyyy-MM-dd hh:mm:ss";
     */
    var matches = String(date).match(/\d+/g);
    var date = Date.UTC(matches[0],matches[1]-1,matches[2],matches[3],matches[4],matches[5], 0);
    var temp = new Date();
    var localDate = date - temp.getTimezoneOffset()*60;
    localDate = new Date(localDate);
    var o = {
        "M+" :  localDate.getMonth()+1,  //month
        "d+" :  localDate.getDate(),     //day
        "h+" :  localDate.getHours(),    //hour
        "m+" :  localDate.getMinutes(),  //minute
        "s+" :  localDate.getSeconds(), //second
        "q+" :  Math.floor((localDate.getMonth()+3)/3),  //quarter
        "S"  :  localDate.getMilliseconds() //millisecond
    }

    if(/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (localDate.getFullYear()+"").substr(4 - RegExp.$1.length));
    }

    for(var k in o) {
        if(new RegExp("("+ k +")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
        }
    }
    return format;
};